//ssc install estout
//ssc install rwolf2

global replica_dir="<add path to your working directory>"
global data_dir="$replica_dir/data"
global output_dir="$replica_dir/output"

use "$data_dir/panel_simce4b6_sned_studlvl.dta", clear

/*----------------------------------------------------------------------------*/

**# Figure A6: Student outcome discontinuity plots, Grade 6 cohorts
 
/*----------------------------------------------------------------------------*/

global indepvars "sch_municip_pre rural_rbd sch_stno_pre i.tipo_est_num i.mom_edu_pre i.dad_edu_pre i.pad_inc_pre i.sch_gse_pre i.hg i.sned_yr"  
global depvars "mate lect"  

la var mate_post "Grade 6 Math Score"
la var lect_post "Grade 6 Reading Score"

la var treat25 "Full vs. Partial Bonus"
la var treat10 "Partial vs. No Bonus"


/*----------------------------------------------------------------------------- 

	Graphs at school level
	source: https://opr.princeton.edu/workshops/Downloads/2015May_StataGraphicsKoffman.pdf

*/



collapse (mean) mate_post lect_post (first) st_ind25 st_ind10  , by(rbd sned_yr)

global indepvars "mate_post lect_post" // 

la var mate_post "Grade 6 Math Score"
la var lect_post "Grade 6 Reading Score"


foreach i in 25{
foreach y of global indepvars{
local label_`y': variable label `y'

rdplot `y' st_ind`i'   if abs(st_ind`i') <= 1.5, h(1.5)  graph_options(legend(off) graphregion(color(white)) xtitle("SNED index centered at zero") /*ytitle("`label_`y''")*/ title("`label_`y'', 100% vs. 60%") xlab(-1.5(0.5)1.5) ylab(230(15)265))   binselect(esmv)  kernel(uni) p(2) masspoints(off)   ///
 
graph export "$output_dir/graph_6b4_`y'_`i'.png", as(png) replace

}
}

foreach i in 10{
foreach y of global indepvars{
local label_`y': variable label `y'

rdplot `y' st_ind`i'   if abs(st_ind`i') <= 1.5, h(1.5)  graph_options(legend(off) graphregion(color(white)) xtitle("SNED index centered at zero") /*ytitle("`label_`y''")*/ title("`label_`y'', 60% vs. none") xlab(-1.5(0.5)1.5) ylab(230(15)265))   binselect(esmv)  kernel(uni) p(2) masspoints(off)   ///
 
graph export "$output_dir/graph_6b4_`y'_`i'.png", as(png) replace

}
}
